window.onload=function(){
    //定时器每秒调用一次fnDate（）
    setInterval(function(){fnDate();},1000);
    }
//js获取当前时间
function fnDate(){
    let Ti=document.getElementById("time");
    let date=new Date();
    let year=date.getFullYear();
    let month=date.getMonth();
    let data=date.getDate();
    let hours=date.getHours();
    let minute=date.getMinutes();
    let second=date.getSeconds();
    let time=year+"-"+fnW((month-1))+"-"+fnW(data)+" "+fnW(hours)+":"+fnW(minute)+":"+funW(second);
    Ti.innerHTML=time;
}
//补位 当某个字段不是两位数时补0
function fnW(str){
    let num;
    str>10?num=str:num="0"+str;
    return num;
}